<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="800px"
  >
    <div class="form-box">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
      >
        <el-form-item label="监控名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入" />
        </el-form-item>
        <br />
        <el-form-item label="监控类型" prop="type">
          <el-select :disabled="isEdit" v-model="form.type" @change="form.intervalDays=''">
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="(item,key) in taskTypeOptions"
              :key="key"
            ></el-option>
          </el-select>
        </el-form-item><br/>
        
        <el-form-item label="检查间隔" prop="intervalDays">
          <el-select v-model="form.intervalDays" v-if="form.type!=2">
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="(item,key) in days1"
              :key="key"
            ></el-option>
          </el-select>
          <el-select v-model="form.intervalDays" v-if="form.type==2">
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="(item,key) in days2"
              :key="key"
            ></el-option>
          </el-select>
          
        </el-form-item>
        <!-- <div class="tip">
            提示：检查间隔(执行间隔，如间隔1天，代表1天执行一次监测)
          </div> -->
        <el-form-item label="备注" prop="remark">
          <el-input
            style="width: 400px"
            :rows="4"
            type="textarea"
            v-model="form.remark"
            placeholder="请输入"
          />
        </el-form-item>
        <div class="center">
          <el-button @click="close()">取消</el-button>
          <el-button
            type="primary"
            @click="submitForm('form')"
            v-loading="loading"
            >提交</el-button
          >
        </div>
      </el-form>
    </div>
  </el-dialog>
</template>
<script>
import checkPhoneApi from "@/api/gameConfig/checkPhonePx";
export default {
  name: "addSupplyConfig",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      taskTypeOptions:
      {
        1:{
          label: "掉绑监控",
          value: 1,
          type:'success'
        },
        2:{
          label: "转手监控",
          value: 2,
          type:'danger'
        }
      },
      days1:{
        1:{
          label:'1天',
          value:1,
          type:''
        },
        3:{
          label:'3天',
          value:3,
          type:'success'
        },
        7:{
          label:'7天',
          value:7,
          type:'warning'
        },
        15:{
          label:'15天',
          value:15,
          type:'dnager'
        },
      } ,
      days2:{
        3:{
          label:'3天',
          value:3,
          type:'success'
        },
        5:{
          label:'5天',
          value:5,
          type:''
        },
        7:{
          label:'7天',
          value:7,
          type:'warning'
        },
        10:{
          label:'10天',
          value:10,
          type:''
        },
        15:{
          label:'15天',
          value:15,
          type:'success'
        },
      } ,
   
      // 表单参数
      form: {
        type: "",
        name: "",
        intervalDays: "",
        state: 1,
        remark: ""
      },
      title: "新增",
      isEdit: false,
      flag: "",
      rules: {
        name: [
          { required: true, message: "请输入", trigger: "blur" },
        ],
        type: [
          { required: true, message: "请输入", trigger: "change" },
        ],
        intervalDays: [{ required: true, message: "请输入", trigger: "change" }],
     
      },
    };
  },
  created() {},
  methods: {
    // 打开弹窗
    open(flag,row) {
      this.dialogVisible = true;
      if(flag=='edit'){
        this.title = "编辑";
        this.isEdit = true;
        this.form = {...row}
      }else{
        this.title = "新增";
        this.isEdit = false;
        this.$nextTick(() => {
          this.reset();
        });
      }
      
    },
    // 重置
    reset() {
      this.form= {
        type: "",
        name: "",
        intervalDays: "",
        state: 1,
        remark: ""
      }
      this.$refs.form.resetFields();
    },
    // // 选择用户改变
    // iotypeChange(e) {
    //   this.allUsers.forEach(r => {
    //     if (r.userId == e) {
    //       this.form.name = r.nickName
    //     }
    //   })
    // },
    // // 获取全部用户
    // getAllUserList() {
    //   supplyConfigApi.getAllUserList().then(res => {
    //     this.allUsers = res.rows
    //   })
    // },
    /** 查询详情进行回显 */
    // handleUpdate(row) {
    //   //console.log("%c Line:132 🍕 row", "color:#465975", row);
    //   this.form = JSON.parse(JSON.stringify(row))
    // },
    submitForm(formName) {
      this.$refs["" + formName].validate((valid) => {
        if (valid) {
          if (this.isEdit) {
            // 编辑
            checkPhoneApi.editMonitorTask(this.form).then(res => {
              this.$message.success(res.msg);
              this.dialogVisible = false;
              this.$parent.getList();
            });
          } else {
            // 新增
            checkPhoneApi.addMonitorTask(this.form).then((res) => {
              this.$message.success(res.msg);
              this.dialogVisible = false;
              this.$parent.getList();
            });
          }
        } else {
          this.$alert("请填写完整！");
        }
      });
    },
    close() {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="css">
.tip {
  color: rgb(0, 162, 255);
  padding-left: 110px;
}
</style>
